package com.sskj.b70.v.activity;

import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.scwang.smartrefresh.header.BezierCircleHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sskj.b70.R;
import com.sskj.b70.common.App;
import com.sskj.b70.common.adapter.BaseAdapter;
import com.sskj.b70.common.adapter.ViewHolder;
import com.sskj.b70.common.widget.ToolBarLayout;
import com.sskj.b70.m.bean.FundRecordBean;
import com.sskj.b70.p.activity.FunTransferRecordPresenter;
import com.sskj.b70.utils.DateUtil;
import com.sskj.b70.v.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

/**
 * <pre>基金管理 --> 基金划转 --> 资金明细
 *     author : lee
 *     desc   : 资金明细
 *     version: 1.0
 * </pre>
 */
public class FundTransferRecordActivity extends BaseActivity<FunTransferRecordPresenter> {


    @BindView(R.id.toolBar)
    ToolBarLayout mToolBar;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.fund_record_recyclerview)
    RecyclerView mFundRecordRecyclerview;
    @BindView(R.id.fund_record_smartrefresh)
    SmartRefreshLayout mFundRecordSmartrefresh;
    private BaseAdapter<FundRecordBean.ListBean> mAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_fund_transfer_record;
    }

    @Override
    public FunTransferRecordPresenter getPresenter() {
        return new FunTransferRecordPresenter();
    }

    @Override
    protected void initView() {
        mToolBar.setLeftButtonOnClickLinster(v -> finish());
        mTitle.setText(App.INSTANCE.getString(R.string.strFundTransferRecordActivity0));

        mFundRecordSmartrefresh.setRefreshHeader(new BezierCircleHeader(mActivity));

        mFundRecordSmartrefresh.setOnRefreshListener(loadmorelistener -> {
            mFundRecordSmartrefresh.finishRefresh();
            mPresenter.requestData(true);
        });
        mFundRecordSmartrefresh.setOnLoadMoreListener(loadmorelistener -> {
            mFundRecordSmartrefresh.finishLoadMore();
            mPresenter.requestData(false);
        });

        mFundRecordSmartrefresh.autoRefresh();

        mFundRecordRecyclerview.setLayoutManager(new LinearLayoutManager(mActivity));
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mActivity, LinearLayoutManager.VERTICAL);
        dividerItemDecoration.setDrawable(getResources().getDrawable(R.drawable.shape_item_decoration));
        mFundRecordRecyclerview.addItemDecoration(dividerItemDecoration);

        mAdapter = new BaseAdapter<FundRecordBean.ListBean>(R.layout.item_fund_transfer, null, mFundRecordRecyclerview) {
            @Override
            public void bind(ViewHolder holder, FundRecordBean.ListBean item) {
                holder.setText(R.id.item_fund_transfer_type, item.getType() == 1? App.INSTANCE.getString(R.string.strFundTransferRecordActivity1) : App.INSTANCE.getString(R.string.strFundTransferRecordActivity2));
                holder.setText(R.id.item_fund_transfer_status, item.getState() == 1? App.INSTANCE.getString(R.string.strFundTransferRecordActivity3) : App.INSTANCE.getString(R.string.strFundTransferRecordActivity4));
                holder.setText(R.id.item_fund_transfer_time, DateUtil.getDateFormat(item.getAddtime() * 1000, DateUtil.PATTERN_J));
                holder.setText(R.id.item_fund_transfer_balance, item.getBf_ttl());
                holder.setText(R.id.item_fund_transfer_value, item.getBf_num());
            }
        };
        mAdapter.setEmtyView();
    }

    public void onDataSuccess(List<FundRecordBean.ListBean> list, boolean isRefresh) {
        if (isRefresh){
            mAdapter.setNewData(list);
        }else {
            mAdapter.addData(list);
        }
    }
}
